Hi! I will iterate with a for-loop over all modules in the current folder in that way, that I can assign this current module (which is in every iteration of the for-loop a another module) to a function which expects modules.
I call with this code my function: Folder f = current iterateExportModuleToExcel(f)
The function goes like that:
void iterateExportModuleToExcel(Folder f)
The Problem now is, that the for loop obviously don't iterate over the modules, because I don't get the print statement within the for-loop. What is false in my function? tobi_mehrl - Mon Apr 27 06:35:16 EDT 2015 |
Re: Iterate over alle modules in the current folder? Try something like: Item i for i in current Folder do |
Re: Iterate over alle modules in the current folder? doors36677 - Mon Apr 27 07:18:32 EDT 2015 Try something like: Item i for i in current Folder do Thank you. This suggestion is running now. But now, can you say me, that I come from Item i (which has obviously the information from the module...) to a module m? Is there any cast from Item to Module?
If I declare a variable Module m and assign: m = module(i) in the for-loop and if i run the code, I don't get any warnings. But if I write additionally print name(m) I get any warnings. The function now is looking like that:
void iterateExportModuleToExcel()
//Can I write some type of type-cast? How can I get Module m depending on Item i?
I need a module in each iteration becaus I have to call a function with parameter Module in each iteration...
Can you help me?
|
Re: Iterate over alle modules in the current folder? tobi_mehrl - Mon Apr 27 14:45:05 EDT 2015 Thank you. This suggestion is running now. But now, can you say me, that I come from Item i (which has obviously the information from the module...) to a module m? Is there any cast from Item to Module?
If I declare a variable Module m and assign: m = module(i) in the for-loop and if i run the code, I don't get any warnings. But if I write additionally print name(m) I get any warnings. The function now is looking like that:
void iterateExportModuleToExcel()
//Can I write some type of type-cast? How can I get Module m depending on Item i?
I need a module in each iteration becaus I have to call a function with parameter Module in each iteration...
Can you help me?
Go back to code I gave -- name I is name of module I. e., print (name i) "\n" It is all in the help file for dxl
|
Re: Iterate over alle modules in the current folder? tobi_mehrl - Mon Apr 27 14:45:05 EDT 2015 Thank you. This suggestion is running now. But now, can you say me, that I come from Item i (which has obviously the information from the module...) to a module m? Is there any cast from Item to Module?
If I declare a variable Module m and assign: m = module(i) in the for-loop and if i run the code, I don't get any warnings. But if I write additionally print name(m) I get any warnings. The function now is looking like that:
void iterateExportModuleToExcel()
//Can I write some type of type-cast? How can I get Module m depending on Item i?
I need a module in each iteration becaus I have to call a function with parameter Module in each iteration...
Can you help me?
Hi Toby You can use a recursive algorithm to step through all items of your Database
void checkDatabaseItem(Item itmWork) {
if (type(itmWork) == "Project") {
++iCountProjects;
Item itmHelp;
for itmHelp in folder(itmWork) do {
checkDatabaseItem(itmHelp);
}
}
if (type(itmWork) == "Folder") {
++iCountFolder;
Item itmHelp;
for itmHelp in folder(itmWork) do {
checkDatabaseItem(itmHelp);
}
}
if (type(itmWork) == "Formal") {
ModName_ mdlWork = module(fullName(itmWork));
if (isDeleted(mdlWork)) {
++iCountModulesDeleted;
} else {
++iCountModules;
// Do something with your module
}
}
} // checkDatabaseItem
Best regards Wolfgang |
Re: Iterate over alle modules in the current folder? tobi_mehrl - Mon Apr 27 14:45:05 EDT 2015 Thank you. This suggestion is running now. But now, can you say me, that I come from Item i (which has obviously the information from the module...) to a module m? Is there any cast from Item to Module?
If I declare a variable Module m and assign: m = module(i) in the for-loop and if i run the code, I don't get any warnings. But if I write additionally print name(m) I get any warnings. The function now is looking like that:
void iterateExportModuleToExcel()
//Can I write some type of type-cast? How can I get Module m depending on Item i?
I need a module in each iteration becaus I have to call a function with parameter Module in each iteration...
Can you help me?
Module module(Item itemRef) Returns a handle of type Module for itemRef if itemRef is an open module. Otherwise, it returns null. However, an Item can be of different types, so you should first check that the item is a module, if it is not open you have to open the module to get a handle of type Module. As you have the name of the Item that is easily done using the function 'read' for example.
/sekrbo |
Re: Iterate over alle modules in the current folder? This function will recursively loop through a Folder to find all the Modules contained within. If Modules should only be found in the folder and not the folders within the current folder, simply remove the recursive call to loopThroughFolder.
void loopThroughFolder(Folder f)
{
Module mod = null;
Item i;
if(null == f)
return;
for i in f do
{
if(type(i) == "Folder")
loopThroughFolder(folder(i));
else if(type(i) == "Formal")
{
mod = read(fullName(i), false);
print(name(mod) "\n");
//do whatever else with mod.
}
}
}
|
Re: Iterate over alle modules in the current folder? Thanks a lot for your helpfully answers! However, I have addtionally problems, with my code. I start a own-made function with name "exportModuleToExcel", which I start during if you click a Button in a DialogBox. The code goes like that: exportButtonDBE = apply( excelExportDB, exportButtonLabel, exportModuleToExcel ) My requirement is, to start the function "exportModuleToExcel" several times. Several times means: Start this function as often as a for-loop (e.g.) finds modules whicht content must be exportet to excel. Is there any possibility to code this behaviour? |